package com.graph;

import java.util.Objects;

/**
 * @Author: tgy
 * @Date: 2020-10-26 09:56
 */
public abstract class AbstractGraph<V,E> implements Graph<V,E> {

    interface Operations<E>{

        int cpm(E e1,E e2);

        E add(E e1, E e2);

        E zero();
    }

    protected Operations<E> operations;

    public AbstractGraph() {

        this(null);
    }

    public AbstractGraph(Operations<E> operations) {
        this.operations = operations;
    }


    protected int compare(E e1, E e2) {

        if (Objects.nonNull(operations)) {

            return operations.cpm(e1,e2);
        }

        return ((Comparable)e1).compareTo(e2);
    }
}
